rm(list = ls())

## SET YOUR FILE PATH
setwd("~/Dropbox/Immigration/Analysis/Policy Diffusion/Replication Files/")

library(haven)
library(dplyr)
library(ggplot2)
library(corrgram)
library(corrplot)
library(RColorBrewer)

data <- read_dta('main_corrgram.dta')

names(data) <- c("+ 1 SD Liberalization", "# 1 SD Liberalizations", "+ 0.5 SD Liberalization", "# 0.5 SD Liberalizations", "+ 0.25 SD Liberalization", "# 0.25 SD Liberalizations", "- 1 SD Restriction", "# 1 SD Restriction", "- 0.5 SD Restriction", "# 0.5 SD Restriction", "- 0.25 SD Restriction", "# 0.25 SD Restriction",  "Intense, Proximate Civil War", "Elite Kin Discrimination", "DAC Aid/GDP", "GDP/Capita", "Negative GDP Shock", "Population", "Democracy", "Former Soviet Union", "Trade-to-GDP Ratio", "Regional Liberalization", "Legal Origins Liberalization", "Top Aid Recipient Liberalization")

newdata <- na.omit(data)

corrdata <- cor(newdata)

head(round(corrdata,3))

par( ps=9)

corrplot(corrdata, method="circle", col=brewer.pal(n=6, name="RdYlBu"), tl.col="black", tl.cex = .6, tl.srt=90, bg="gray96")

dev.copy(png,'corrgram_main.png', width = 5, height = 5, units = 'in', res = 300)
dev.off()